home *** CD-ROM | disk | FTP | other *** search
/ Champak 122 / Vol 122.iso / games / sketchbo.swf / scripts / __Packages / XMLConstruct.as next >
Encoding:
Text File  |  2011-01-06  |  2.9 KB  |  119 lines

  1. class XMLConstruct extends XMLConstructNode
  2. {
  3.    var XMLEventDispatcher;
  4.    var attributes;
  5.    var rootVal = "firstChild";
  6.    function XMLConstruct(input)
  7.    {
  8.       super();
  9.       this.XMLEventDispatcher = new mx.events.EventDispatcher();
  10.       if(input != undefined)
  11.       {
  12.          this.parse(input);
  13.       }
  14.    }
  15.    function addEventListener(event, listener)
  16.    {
  17.       this.XMLEventDispatcher.addEventListener(event,listener);
  18.    }
  19.    function removeEventListener(event, listener)
  20.    {
  21.       this.XMLEventDispatcher.removeEventListener(event,listener);
  22.    }
  23.    function get stripRoot()
  24.    {
  25.       if(this.rootVal eq "firstChild")
  26.       {
  27.          return true;
  28.       }
  29.       return false;
  30.    }
  31.    function set stripRoot(z)
  32.    {
  33.       if(z eq true)
  34.       {
  35.          this.rootVal = "firstChild";
  36.       }
  37.       else
  38.       {
  39.          this.rootVal = undefined;
  40.       }
  41.    }
  42.    function parse(input)
  43.    {
  44.       var _loc7_ = undefined;
  45.       var _loc3_ = undefined;
  46.       var _loc2_ = undefined;
  47.       var _loc4_ = undefined;
  48.       _loc3_ = this.parseNode(input[this.rootVal],new XMLConstructNode());
  49.       for(_loc2_ in this)
  50.       {
  51.          if(this[_loc2_] instanceof Array)
  52.          {
  53.             delete this[_loc2_];
  54.          }
  55.       }
  56.       this.attributes = undefined;
  57.       _loc4_ = [];
  58.       for(_loc2_ in _loc3_)
  59.       {
  60.          if(_loc2_ eq "attributes")
  61.          {
  62.             for(var _loc5_ in _loc3_[_loc2_])
  63.             {
  64.                this.addAttribute(_loc5_,_loc3_[_loc2_][_loc5_]);
  65.             }
  66.          }
  67.          else
  68.          {
  69.             _loc4_.push(_loc2_);
  70.          }
  71.       }
  72.       for(_loc2_ in _loc4_)
  73.       {
  74.          this[_loc4_[_loc2_]] = _loc3_[_loc4_[_loc2_]];
  75.       }
  76.    }
  77.    function parseNode(xObj, obj)
  78.    {
  79.       var _loc2_ = undefined;
  80.       var _loc5_ = undefined;
  81.       var _loc4_ = undefined;
  82.       var _loc3_ = undefined;
  83.       var _loc8_ = xObj.attributes;
  84.       for(_loc2_ in _loc8_)
  85.       {
  86.          obj.addAttribute(_loc2_,_loc8_[_loc2_]);
  87.       }
  88.       for(_loc2_ in xObj.childNodes)
  89.       {
  90.          _loc3_ = xObj.childNodes[_loc2_];
  91.          _loc5_ = _loc3_.nodeName;
  92.          _loc4_ = _loc3_.nodeType;
  93.          if(_loc4_ == 3)
  94.          {
  95.             obj._value = _loc3_.nodeValue;
  96.          }
  97.          else if(_loc4_ == 1 && _loc5_ != null)
  98.          {
  99.             var _loc7_ = this.parseNode(_loc3_,new XMLConstructNode());
  100.             obj.appendChild(_loc5_,_loc7_);
  101.          }
  102.       }
  103.       return obj;
  104.    }
  105.    function load(file)
  106.    {
  107.       var thisObj = this;
  108.       var tXML = new XML();
  109.       tXML.ignoreWhite = true;
  110.       tXML.load(file);
  111.       tXML.onLoad = function(success)
  112.       {
  113.          thisObj.parse(tXML);
  114.          thisObj.onLoad(success);
  115.          thisObj.XMLEventDispatcher.dispatchEvent({type:"onLoad",target:thisObj,success:success});
  116.       };
  117.    }
  118. }
  119.